package aad.storyboard.controller;

import java.util.Observer;

import aad.storyboard.R;
import aad.storyboard.model.*;
import aad.storyboard.view.BackButton;
import aad.storyboard.view.GraphicView;
import aad.storyboard.view.NextButton;
import aad.storyboard.view.PauseButton;
import aad.storyboard.view.ScriptView;
import aad.storyboard.view.StaticScriptView;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.SeekBar;
import android.widget.RelativeLayout;
import android.widget.ViewFlipper;

public class GUIComposer extends Thread{
	
	private static GUIComposer instance = new GUIComposer();
	private int fps = 25; 
	private View mainLayout;
	private GraphicView graphicalView;
	private StaticScriptView  scriptView;
	private WebView  wikiView;
	private StoryTimer timer;
	private ViewFlipper flipper;
	private Activity activity;
	
	private AudioPlayer audioPlayer;
	
	
	private SceneController sc;
	private NavigationController nc;
	
	
	public static GUIComposer getInstance(){
		return instance;
	}
	
	 
	private void GUIController(){
	}
	
	
	
	public void setupGUI(Story s, Activity a, int mL){

	    this.mainLayout = (View) a.findViewById(R.id.mainlayout);
		Log.e("hallo",this.mainLayout+"");
		this.activity=a;
	    this.flipper = (ViewFlipper) a.findViewById(R.id.flipper);  	   
		SeekBar volControl = (SeekBar) a.findViewById(R.id.volbar);	

		nc=new NavigationController(volControl, this.activity);	  
	   
	 
	   
	  this.graphicalView= (GraphicView)a.findViewById(R.id.graphicView);	   
	  this.scriptView=(StaticScriptView)a.findViewById(R.id.scriptView);
	  
	  RelativeLayout wiki=(RelativeLayout)activity.findViewById(R.layout.wikipage);
	  this.wikiView=(WebView)activity.findViewById(R.id.wikiView);
	  	  
	  //WebSettings ws = scriptView.getSettings();
	 // ws.setJavaScriptEnabled(true);  
	  //JavaScriptInterface intf=new JavaScriptInterface(activity, wikiView, flipper);
	  //scriptView.setJavaScriptInterface(intf);
	   
	   /*
	   btn2.setOnClickListener(new NavigationOnClickListener(a, flipper));
	   */
	   
	   graphicalView.setOnTouchListener(new ViewTouchListener(s));
	   
	    
	    NavigationOnClickListener list= new NavigationOnClickListener(a, flipper);
	    PauseButton pause=(PauseButton)a.findViewById(R.id.pause);
	    pause.setOnClickListener(list);
	    BackButton back=(BackButton)a.findViewById(R.id.backward);
	    back.setOnClickListener(list);
	    NextButton next=(NextButton)a.findViewById(R.id.forward);
	    next.setOnClickListener(list);
		
	    
	     //Drag and Drop
	    DragDropManager.getInstance().init(graphicalView);
	    DropListener dropzoneListener=DragDropManager.getInstance().getDropzoneListener();
		
		// Setup the 2 drop zones
		DropSpot dropzone1 = new DropSpot(dropzoneListener);
		dropzone1.setPosX(200);
		dropzone1.setPosY(200);
		
		Paint p=new Paint();
		p.setColor(Color.TRANSPARENT);
		dropzone1.setPaint(p);
		DragDropManager.getInstance().addDropZone(dropzone1);

		DropSpot dropzone2 = new DropSpot(dropzoneListener);
		dropzone2.setPosX(300);
		dropzone2.setPosY(300);
		
		DragDropManager.getInstance().addDropZone(dropzone2);			
		dropzone1.setPaint(p);	
	 
	}
	
	
	public View getMainView(){
		return this.mainLayout;
	}
	
	public View getGraphicalView(){
		return this.graphicalView;
	}

	public int getFps(){
		return this.fps;
	}


	public StaticScriptView getScriptView() {
		return this.scriptView;
	}
	
	public void setMainView(View v){
		this.mainLayout = v;
	}


	public ViewFlipper getFlipper() {		
		return flipper;
	}


	public WebView getWikiView() {		
		return wikiView;
	}
			
}
